Skip to content

[PATCH 7/7] [clang] improve NestedNameSpecifier: LLDB changes #149949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Jul 22, 2025

Patch series starting at #147835

@mizvekov mizvekov self-assigned this Jul 22, 2025
@mizvekov mizvekov requested a review from JDevlieghere as a code owner July 22, 2025 01:01
@llvmbot llvmbot added the lldb label Jul 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-lldb

Author: Matheus Izvekov (mizvekov)

Changes

Test run of the LLDB CI, just checking if anything needs to be updated there.


Full diff: https://github.com/llvm/llvm-project/pull/149949.diff

1 Files Affected:

  • (added) lldb/DELETE.ME ()
diff --git a/lldb/DELETE.ME b/lldb/DELETE.ME
new file mode 100644
index 0000000000000..e69de29bb2d1d

@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch from 3c8cbad to 7c873c4 Compare July 22, 2025 05:53
@mizvekov mizvekov changed the title Draft: [PATCH 7/7] [clang] improve NestedNameSpecifier: LLDB changes [PATCH 7/7] [clang] improve NestedNameSpecifier: LLDB changes Jul 22, 2025
@mizvekov mizvekov requested a review from Michael137 July 22, 2025 05:55
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch from 7c873c4 to 2c01149 Compare July 22, 2025 06:33
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-6 branch from 998f226 to 47b79ce Compare July 22, 2025 19:53
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch 2 times, most recently from 285569d to 968ecb4 Compare July 22, 2025 20:05
Copy link

github-actions bot commented Jul 22, 2025

✅ With the latest revision this PR passed the Python code formatter.

@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch 11 times, most recently from b8c6168 to ea97cf5 Compare July 24, 2025 04:53
Copy link
Member

@Michael137 Michael137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm yea I don't think we want to be losing the scope qualifiers for the typenames. What does LLDB have to do to retain those?

@mizvekov
Copy link
Contributor Author

Hmmmm yea I don't think we want to be losing the scope qualifiers for the typenames. What does LLDB have to do to retain those?

The answer to that depends on what LLDB wants and can do here.

The status quo is, the types produced in the places changed here are not valid as-written types, as they lacked an ElaboratedType. Clang will currently print types lacking an ElaboratedType as if they were fully qualified, with a synthesized name qualifier.

This is used to distinguish canonical from non-canonical types, and the motivation is that we find it more appropriate to print canonical types as fully qualified when they appear in diagnostics and such.

Now with this patch series, we retain the ability to distinguish canonical RecordTypes and EnumTypes, and still print those as fully qualified. But a mis-feature of the status quo is removed: the same would work for TypedefTypes, if they lacked an ElaboratedType on top, then we would fully qualify them when printing.

But this was not an intentional feature, and it lacks motivation, as TypedefTypes never appear in canonical types.
This patch does not create an AST representation for such a TypedefType, beyond what you can do synthesizing a name qualifier yourself.

Now, does LLDB want to keep fully qualified names here, or does it want these to be printed as-written?

Changing this back to the status quo is more straight-forward, we just need to synthesize fully qualified types.

This is taking me a while because it's currently very difficulty for me to get a functional LLDB workflow on MacOS, so
I am currently relying only on the CI job to test and debug this.

To change this to as-written, we would need to figure out if we have a source for this information first, if we store and can retrieve those from all of the Debug info formats we support.

@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch from ea97cf5 to ba9b546 Compare July 27, 2025 21:57
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 27, 2025
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-6 branch from 47b79ce to ff2bfb3 Compare August 5, 2025 01:33
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch 2 times, most recently from bd69857 to b894c91 Compare August 5, 2025 17:15
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-6 branch 2 times, most recently from 52b954b to bcd1eeb Compare August 5, 2025 17:30
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch 2 times, most recently from 24638a4 to 552fc80 Compare August 5, 2025 17:33
@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 5, 2025

@Michael137 this is ready for another look.

@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch from 552fc80 to 4abdd23 Compare August 5, 2025 18:22
Copy link
Member

@Michael137 Michael137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for ensuring we don't lose the scope in our typenames! LGTM

@Michael137
Copy link
Member

@mizvekov do you have a macOS machine handy to test this on? Or do you want me to try?

@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 6, 2025

@mizvekov do you have a macOS machine handy to test this on? Or do you want me to try?

I don't think there is anything macOS specific about this change.

My main development machine is macOS, and I always struggled with testing LLDB on it.

But I finally setup a Linux VM on it, and all that went fine without a single hitch. Besides, our CI is Linux based, and that passes as well.

@Michael137
Copy link
Member

@mizvekov do you have a macOS machine handy to test this on? Or do you want me to try?

I don't think there is anything macOS specific about this change.

My main development machine is macOS, and I always struggled with testing LLDB on it.

But I finally setup a Linux VM on it, and all that went fine without a single hitch. Besides, our CI is Linux based, and that passes as well.

There are tests that only run on macOS. I just want to avoid a situation where we have to revert the entire patch series because of some macOS post-merge test failures. Ideally we'd catch these pre-merge on Github, but that's currently not set up unfortunately.

Since you don't have the setup, let me run the tests. I'll report back tomorrow

@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 6, 2025

@mizvekov do you have a macOS machine handy to test this on? Or do you want me to try?

I don't think there is anything macOS specific about this change.

My main development machine is macOS, and I always struggled with testing LLDB on it.

But I finally setup a Linux VM on it, and all that went fine without a single hitch. Besides, our CI is Linux based, and that passes as well.

There are tests that only run on macOS. I just want to avoid a situation where we have to revert the entire patch series because of some macOS post-merge test failures. Ideally we'd catch these pre-merge on Github, but that's currently not set up unfortunately.

Since you don't have the setup, let me run the tests. I'll report back tomorrow

Ah okay. Any easy way for me to tell which are these tests?

I can run some of the tests locally, but not all of them passes, but that's the case for main branch llvm as well.

@Michael137
Copy link
Member

Hmmm getting this error when building the patch series locally

Undefined symbols for architecture arm64:
  "clang::NestedNameSpecifierLoc::getTypeLoc() const", referenced from:
      clang::RecursiveASTVisitor<(anonymous namespace)::RetainPtrCtorAdoptChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) const::LocalVisitor>::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc) in libclangStaticAnalyzerCheckers.a[132](RetainPtrCtorAdoptChecker.cpp.o)

Any ideas?

@mizvekov do you have a macOS machine handy to test this on? Or do you want me to try?

I don't think there is anything macOS specific about this change.

My main development machine is macOS, and I always struggled with testing LLDB on it.

But I finally setup a Linux VM on it, and all that went fine without a single hitch. Besides, our CI is Linux based, and that passes as well.

There are tests that only run on macOS. I just want to avoid a situation where we have to revert the entire patch series because of some macOS post-merge test failures. Ideally we'd catch these pre-merge on Github, but that's currently not set up unfortunately.
Since you don't have the setup, let me run the tests. I'll report back tomorrow

Ah okay. Any easy way for me to tell which are these tests?

Hmm not that I'm aware of

@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 6, 2025

Hmmm getting this error when building the patch series locally

Undefined symbols for architecture arm64:
  "clang::NestedNameSpecifierLoc::getTypeLoc() const", referenced from:
      clang::RecursiveASTVisitor<(anonymous namespace)::RetainPtrCtorAdoptChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) const::LocalVisitor>::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc) in libclangStaticAnalyzerCheckers.a[132](RetainPtrCtorAdoptChecker.cpp.o)

Any ideas?

That's probably missing a #include "clang/AST/NestedNameSpecifier.h" somewhere, where it was previously relying on that being indirectly included.

@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 6, 2025

We do include it from RecursiveASTVisitor.h though.

Is this is building LLVM from a clean build directory?

@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 6, 2025

That builds cleanly on a MacOS machine and the tests for that checker pass.

If you can still reproduce that even from a clean build, please share repro steps.

@theotherjimmy
Copy link

I would approve if I could. 👍

@Michael137
Copy link
Member

Clean build succeeded.

These tests fail on macOS:

********************
********************
Unresolved Tests (3):
  lldb-api :: commands/expression/import-std-module/list/TestListFromStdModule.py
  lldb-api :: commands/expression/import-std-module/non-module-type-separation/TestNonModuleTypeSeparation.py
  lldb-api :: commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 6, 2025

Clean build succeeded.

These tests fail on macOS:

********************
********************
Unresolved Tests (3):
  lldb-api :: commands/expression/import-std-module/list/TestListFromStdModule.py
  lldb-api :: commands/expression/import-std-module/non-module-type-separation/TestNonModuleTypeSeparation.py
  lldb-api :: commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Thanks, I'll see if I can reproduce locally. Mind sharing the logs meanwhile so I can compare?

@Michael137
Copy link
Member

Attached the test log

test-failures.txt

@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 8, 2025

Thanks. Unfortunately those are some of the tests which always fail for me.

Here is how they fail:

/Users/mizvekov/Repos/llvm/2/build/rwd/bin/clang++  -std=c++11 -g -O0 -isysroot "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk" -arch arm64  -I/Users/mizvekov/Repos/llvm/2/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/Users/mizvekov/Repos/llvm/2/build/rwd/tools/lldb/include -I/Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list -I/Users/mizvekov/Repos/llvm/2/lldb/packages/Python/lldbsuite/test/make -include /Users/mizvekov/Repos/llvm/2/lldb/packages/Python/lldbsuite/test/make/test_common.h  -fno-limit-debug-info    -nostdlib++ -nostdinc++ -cxx-isystem /Users/mizvekov/Repos/llvm/2/build/rwd/include/c++/v1  --driver-mode=g++ -MT main.o -MD -MP -MF main.d -c -o main.o /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
/Users/mizvekov/Repos/llvm/2/build/rwd/bin/clang  main.o -g -O0 -isysroot "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk" -arch arm64  -I/Users/mizvekov/Repos/llvm/2/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/Users/mizvekov/Repos/llvm/2/build/rwd/tools/lldb/include -I/Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list -I/Users/mizvekov/Repos/llvm/2/lldb/packages/Python/lldbsuite/test/make -include /Users/mizvekov/Repos/llvm/2/lldb/packages/Python/lldbsuite/test/make/test_common.h  -fno-limit-debug-info     -L/Users/mizvekov/Repos/llvm/2/build/rwd/lib -Wl,-rpath,/Users/mizvekov/Repos/llvm/2/build/rwd/lib -lc++ --driver-mode=g++ -o "a.out"
ld64.lld: error: undefined symbol: std::terminate()
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol __clang_call_terminate+0xc)

ld64.lld: error: undefined symbol: __cxa_begin_catch
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol __clang_call_terminate+0x8)

ld64.lld: error: undefined symbol: operator delete(void*)
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol void std::__1::__libcpp_deallocate[abi:se220000]<std::__1::__list_node<int, void*>>(std::__1::__type_identity<std::__1::__list_node<int, void*>>::type*, std::__1::__element_count, unsigned long)+0x2c)

ld64.lld: error: undefined symbol: __cxa_throw
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol std::__throw_bad_array_new_length[abi:se220000]()+0x30)

ld64.lld: error: undefined symbol: std::bad_array_new_length::~bad_array_new_length()
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol std::__throw_bad_array_new_length[abi:se220000]()+0x2c)
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol std::__throw_bad_array_new_length[abi:se220000]()+0x28)

ld64.lld: error: undefined symbol: typeinfo for std::bad_array_new_length
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol std::__throw_bad_array_new_length[abi:se220000]()+0x24)
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol std::__throw_bad_array_new_length[abi:se220000]()+0x20)

ld64.lld: error: undefined symbol: std::bad_array_new_length::bad_array_new_length()
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol std::__throw_bad_array_new_length[abi:se220000]()+0x18)

ld64.lld: error: undefined symbol: __cxa_allocate_exception
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol std::__throw_bad_array_new_length[abi:se220000]()+0x10)

ld64.lld: error: undefined symbol: operator new(unsigned long)
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(symbol std::__1::__list_node<int, void*>* std::__1::__libcpp_allocate[abi:se220000]<std::__1::__list_node<int, void*>>(std::__1::__element_count, unsigned long)+0x28)

ld64.lld: error: undefined symbol: __gxx_personality_v0
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(__compact_unwind+0xb0)
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(__compact_unwind+0x2f0)
>>> referenced by /Users/mizvekov/Repos/llvm/2/lldb/test/API/commands/expression/import-std-module/list/main.cpp
>>>               main.o:(__compact_unwind+0x310)
>>> referenced 1 more times

This is even on main branch. I figured this has something to do with the apple libcxx type aware allocator mess, but I wonder if there is a way around that problem I am not aware of.

@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 8, 2025

I managed to fix that, it was some problem with using lld instead of the macOS linker.

@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-6 branch from bcd1eeb to 4dc827b Compare August 9, 2025 05:29
@mizvekov mizvekov force-pushed the users/mizvekov/name-qualification-refactor-7 branch from 4abdd23 to 278d0ca Compare August 9, 2025 05:29
@mizvekov
Copy link
Contributor Author

mizvekov commented Aug 9, 2025

Alright, these three macOS-only test failures are fixed now, I tested locally.

I am moving ahead with the merge.

@mizvekov mizvekov merged commit 69c0d44 into users/mizvekov/name-qualification-refactor-6 Aug 9, 2025
13 of 15 checks passed
@mizvekov mizvekov deleted the users/mizvekov/name-qualification-refactor-7 branch August 9, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category lldb
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants